﻿using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Linq;
using System.Web;
using System.Web.Mvc;

using Bricks.Business.Service.Impl;
using Bricks.Site.Models;
using Bricks.Business.Models.FlowProcess;
using System.Xml;
using System.Web.Script.Serialization;
using Bricks.Business.Service;
using Bricks.Component.Utils;
using Bricks.Site.Web.CommonUtils;
using System.Collections;
using Bricks.Business.Models.Account;
using System.Text;
using Bricks.Component.Utils.Extensions;
using System.Configuration;
using Bricks.Component.Data;
using Bricks.Site.Models.DBViewModel.Contract;
using Bricks.Business.Service.CommonSupport;
using Bricks.Site.Models.DBViewModel.Expense;

namespace Bricks.Site.Web.Controllers
{
    [Export]
    public class ExpenseController : BaseController
    {
        #region 属性
        [Import]
        public IFlowNodeService FlowNodeService { get; set; }
        [Import]
        public IExpenseService ExpenseService { get; set; }
        [Import]
        public IBaklogTaskService BaklogTaskService { get; set; }
        [Import]
        public IFlowUtilsService FlowUtilsService { get; set; }
        [Import]
        public IProcessedTaskService ProcessedTaskService { get; set; }
        [Import]
        public IUserOrgService UserOrgService { get; set; }
        [Import]
        public IOrgInfoService OrgInfoService { get; set; }
        [Import]
        public ICommonContractInfoService CommonContractInfoService { get; set; }
        [Import]
        public IYearPlanService YearPlanService { get; set; }
        [Import]
        public IMonthPlanService MonthPlanService { get; set; }
        #endregion

        /// <summary>
        /// 单据页面初始化
        /// </summary>
        /// <param name="sourceType">来源类型</param>
        /// <param name="processType">处理类型</param>
        /// <param name="sourceID">关联的记录ID</param>
        /// <param name="associatedNodeCode">关联的流程节点编码</param>
        /// <param name="lastUpdateUserDepartment">最后修改人部门</param>
        /// <param name="lastUpdateUser">最后修改人</param>
        /// <param name="expenseID">单据ID</param>
        /// <param name="projectID">项目ID</param>
        /// <param name="contractID">合同ID</param>
        /// <param name="contractType">合同类型</param>
        /// <returns></returns>
        public ActionResult Expense(string sourceType, string processType, string sourceID, string associatedNodeCode, string lastUpdateUserDepartment, string lastUpdateUser, string expenseID, string projectID, string contractID, string contractSource)
        {
            ExpenseView expenseView = null;
            string processdOrCirculatedNodeCode = string.Empty;
            string processdOrCirculatedUserDepartment = string.Empty;
            if (sourceType == "1") //新增付款申请
            {
                string flowCode = GetFlowCode(lastUpdateUserDepartment);
                expenseView = new ExpenseView();
                expenseView.ID = Guid.NewGuid();
                expenseView.ExpenseID = Guid.NewGuid();
                expenseView.FlowCode = flowCode;
                expenseView.ProjectID = projectID.ToGuid();
                expenseView.ContractID = contractID.ToGuid();
                expenseView.ContractSource = contractSource;
                expenseView.RequestMoneyForRequestPerson = 0;
                expenseView.RequestPerson = User.Identity.Name;
                expenseView.RequestPersonName = SystemData.Instance.CurrentUser.RealName;
                expenseView.ApprovalMoney = 0;  //申请金额
                expenseView.ContractStages = 0;  //期次
                expenseView.RequestDate = DateTime.Now;
                expenseView.HandleState = "0";
                expenseView.AssociatedNodeCode = FlowNodeService.GetFlowNodeByNodeCode(flowCode, true, "").NodeCode;
                expenseView.LastUpdateUserDepartment = lastUpdateUserDepartment;
                expenseView.LastUpdateUser = User.Identity.Name;
                processdOrCirculatedNodeCode = expenseView.AssociatedNodeCode;
                processdOrCirculatedUserDepartment = lastUpdateUserDepartment;
            }
            else if (sourceType == "2" && processType == "1") //待办
            {
                expenseView = ExpenseService.GetExpenseBackupByCondition(expenseID, associatedNodeCode, lastUpdateUserDepartment, lastUpdateUser);
            }
            else
            {
                expenseView = ExpenseService.GetExpenseByID(expenseID);
            }
            if (expenseView.ContractStages > 0)
            {
                decimal approvalMoney = expenseView.ApprovalMoney == null ? 0 : Math.Round(Convert.ToDecimal(expenseView.ApprovalMoney), 0);
                expenseView.ContractStagesStr = "第" + expenseView.ContractStages + "期:" + approvalMoney.ToString();
            }

            if (sourceType == "2" || (sourceType == "3" && (processType == "1" || processType == "4" || processType == "5")))
            {
                processdOrCirculatedNodeCode = associatedNodeCode;
                processdOrCirculatedUserDepartment = lastUpdateUserDepartment;
            }
            expenseView.ExpenseBillListJson = "";
            expenseView.SourceType = sourceType;
            expenseView.ProcessType = processType;
            expenseView.SourceID = sourceID;
            expenseView.ProcessdOrCirculatedNodeCode = processdOrCirculatedNodeCode;
            expenseView.ProcessdOrCirculatedUserDepartment = processdOrCirculatedUserDepartment;

            ConstructTools(expenseView);
            return View(expenseView);
        }

        public string GetFlowCode(string userDepartment)
        {
            return "Expense";
        }

        #region 根据功能权限和业务权限构造工具栏菜单按钮
        private void ConstructTools(ExpenseView expenseView)
        {
            List<UIFunctionView> menuActions = base.GetUserMenuActions();
            StringBuilder sb = new StringBuilder();

            //过程管理列表单据双击或单击超链接，只能查看
            if (expenseView.SourceType == "0")
            {
                SetAllDisabled(menuActions, sb);
            }
            //过程管理列表新增按钮,初始化只能保存
            else if (expenseView.SourceType == "1")
            {
                SetOneButtonEnabled(menuActions, sb, "Save");
            }
            #region 待办列表
            else if (expenseView.SourceType == "2")
            {
                //类型为待办
                if (expenseView.ProcessType == "1")
                {
                    foreach (UIFunctionView item in menuActions)
                    {
                        string disabled = "";
                        if (item.ActionCode == "Withdraw" || item.ActionCode == "Receipt" || item.ActionCode == "Reminders")
                        {
                            disabled = "disabled='false'";
                        }
                        else if (item.ActionCode == "Back")
                        {
                            FlowNodeView flowNodeView = FlowNodeService.GetFlowNodeByNodeCode(expenseView.FlowCode, false, expenseView.AssociatedNodeCode);
                            if (flowNodeView.NodeType == 1)
                            {
                                disabled = "disabled='false'";
                            }
                        }
                        else if (item.ActionCode == "Cancel")
                        {
                            FlowNodeView flowNodeView = FlowNodeService.GetFlowNodeByNodeCode(expenseView.FlowCode, false, expenseView.AssociatedNodeCode);
                            if (flowNodeView.NodeLevel > 1 || flowNodeView.NodeType == 1)
                            {
                                disabled = "disabled='false'";
                            }
                        }
                        sb.Append(ToolButton(item, disabled));
                    }
                }
                //类型为传阅
                else
                {
                    foreach (UIFunctionView item in menuActions)
                    {
                        string disabled = "disabled='false'";
                        if (item.ActionCode == "Circulated" || item.ActionCode == "Receipt")
                        {
                            disabled = "";
                        }
                        sb.Append(ToolButton(item, disabled));
                    }
                }
            }
            #endregion

            #region 已办列表
            else if (expenseView.SourceType == "3")
            {
                //流转已办
                if (expenseView.ProcessType == "1")
                {
                    foreach (UIFunctionView item in menuActions)
                    {
                        string disabled = "disabled='false'";
                        if (expenseView.HandleState != "2" && expenseView.HandleState != "3")
                        {
                            if (item.ActionCode == "Withdraw")
                            {
                                //获取撤回到的节点信息
                                FlowNodeView flowNodeView = FlowNodeService.GetFlowNodeByNodeCode(expenseView.FlowCode, false, expenseView.ProcessdOrCirculatedNodeCode);
                                List<FlowNodeView> lstCirculationNode = new List<FlowNodeView>();
                                Dictionary<string, List<FlowNodeView>> dicConditionAndCirculationNode = new Dictionary<string, List<FlowNodeView>>();
                                bool isCanWithdraw = CanWithdraw(flowNodeView, expenseView.ExpenseID.ToString(), expenseView.FlowCode, expenseView.ProcessdOrCirculatedUserDepartment, lstCirculationNode, dicConditionAndCirculationNode);
                                if (isCanWithdraw)
                                {
                                    disabled = "";
                                }
                            }
                            else if (item.ActionCode == "Circulated" || item.ActionCode == "Reminders")
                            {
                                disabled = "";
                            }
                        }
                        sb.Append(ToolButton(item, disabled));
                    }
                }
                //回退已办、终止已办
                else if (expenseView.ProcessType == "2" || expenseView.ProcessType == "3" || expenseView.ProcessType == "6")
                {
                    SetAllDisabled(menuActions, sb);
                }
                //本人传阅或者已阅
                else
                {
                    SetOneButtonEnabled(menuActions, sb, "Circulated");
                }
            }
            #endregion

            //流程消息
            else if (expenseView.SourceType == "4")
            {
                SetAllDisabled(menuActions, sb);
            }

            ViewBag.ToolBarInfo = sb.ToString();
        }

        private void SetAllDisabled(List<UIFunctionView> menuActions, StringBuilder sb)
        {
            foreach (UIFunctionView item in menuActions)
            {
                sb.Append(ToolButton(item, "disabled='false'"));
            }
        }

        private void SetOneButtonEnabled(List<UIFunctionView> menuActions, StringBuilder sb, string code)
        {
            foreach (UIFunctionView item in menuActions)
            {
                string disabled = "disabled='false'";
                if (item.ActionCode == code)
                {
                    disabled = "";
                }
                sb.Append(ToolButton(item, disabled));
            }
        }

        public string ToolButton(UIFunctionView item, string disabled = "")
        {
            return "<a href='javascript:void(0)' id='btn" + item.ActionCode + "' class='easyui-linkbutton' onclick='" + item.MenuCode + "." + item.ActionCode + "()' data-options='plain:true,iconCls:\"" + item.Icon + "\"'" + disabled + ">" + item.ActionName + "</a>";
        }
        #endregion

        #region 判断是否有撤回权限
        /// <summary>
        /// 判断是否有撤回权限
        /// </summary>
        /// <param name="flowNodeView">撤回到的节点信息</param>
        /// <param name="recordID">单据ID</param>
        /// <param name="lstCirculationNode">根据withdrawNodeCode获取要流转的节点列表</param>
        /// <param name="dicConditionAndCirculationNode">根据withdrawNodeCode获取条件节点流转的节点字典</param>
        /// <returns></returns>
        private bool CanWithdraw(FlowNodeView flowNodeView, string recordID, string flowCode, string processUserDepartment, List<FlowNodeView> lstCirculationNode, Dictionary<string, List<FlowNodeView>> dicConditionAndCirculationNode)
        {
            //分析撤回到的节点的XML里面的circulationCell，获取节点Code数组
            string[] arrFlowNodeCode = GetNodeCodeByXMLForCirculation(flowNodeView.NodeXML, recordID);

            //根据第一次获取到的节点数组，获取所有的中间经过的条件节点和流转节点
            foreach (string flowNodeCode in arrFlowNodeCode)
            {
                List<FlowNodeView> lstConditionAndCirculationNode = new List<FlowNodeView>();
                GetConditionAndCirculationNode(flowCode, flowNodeCode, recordID, processUserDepartment, lstCirculationNode, lstConditionAndCirculationNode);
                dicConditionAndCirculationNode.Add(flowNodeCode, lstConditionAndCirculationNode);
            }

            //判断是否流转的节点对应的每个人在待办里面都能找到
            List<BaklogTaskView> lstBaklogTask = BaklogTaskService.GetBaklogTaskByRecordID(recordID);
            foreach (FlowNodeView circulationNode in lstCirculationNode)
            {
                string[] processDepartmentAndPersonArr = circulationNode.DefaultProcessPerson.Split(',');
                foreach (string processDepartmentAndPerson in processDepartmentAndPersonArr)
                {
                    string[] subProcessDepartmentAndPersonArr = processDepartmentAndPerson.Split('|');

                    //是否找不到待办
                    BaklogTaskView existsBaklogTaskView = lstBaklogTask.SingleOrDefault(b => b.CurrentFlowNodeCode == circulationNode.NodeCode && b.CurrentProcessPerson == subProcessDepartmentAndPersonArr[1]);
                    if (existsBaklogTaskView == null)
                    {
                        return false;
                    }

                    //是否点击了保存按钮
                    ExpenseView expenseView = ExpenseService.GetExpenseBackupByCondition(recordID, circulationNode.NodeCode, subProcessDepartmentAndPersonArr[0], subProcessDepartmentAndPersonArr[1]);
                    if (expenseView != null && expenseView.SaveState == "1")
                    {
                        return false;
                    }
                }
            }
            return true;
        }

        /// <summary>
        /// 根据节点的XML获取流转节点Code
        /// </summary>
        /// <param name="nodeXML">节点的XML</param>
        /// <param name="recordID">单据ID</param>
        /// <returns></returns>
        private string[] GetNodeCodeByXMLForCirculation(string nodeXML, string recordID)
        {
            XmlDocument doc = new XmlDocument();
            doc.LoadXml(nodeXML);
            XmlNodeList nodeList = doc.SelectNodes("NodeXML/circulationCell");
            string getType = nodeList[0].SelectSingleNode("getType").InnerText;
            string processNodeCode = string.Empty;
            if (getType.ToLower() == "value")
            {
                processNodeCode = nodeList[0].SelectSingleNode("cellsName").InnerText;
            }
            else
            {
                string functionName = nodeList[0].SelectSingleNode("functionName").InnerText;
                Hashtable para = new Hashtable();
                para.Add("IsGetBusinessData", true);
                para.Add("RecordID", recordID);
                XmlNode paraNode = nodeList[0].SelectSingleNode("functionParam");
                if (paraNode != null)
                {
                    para.Add(paraNode.Name, paraNode.InnerText);
                }
                processNodeCode = FlowUtilsService.ExecuteCommand(functionName, para) as string;
            }
            return processNodeCode.Split(',');
        }

        /// <summary>
        /// 获取所有的中间经过的条件节点和流转节点
        /// </summary>
        /// <param name="flowCode">流程编码</param>
        /// <param name="flowNodeCode">流程节点编码</param>
        /// <param name="recordID">单据ID</param>
        /// <param name="dicCirculationNode">记录流转节点的字典</param>
        /// <param name="lstConditionAndCirculationNode">记录条件节点和流转节点的List</param>
        private void GetConditionAndCirculationNode(string flowCode, string flowNodeCode, string recordID, string processUserDepartment, List<FlowNodeView> lstCirculationNode, List<FlowNodeView> lstConditionAndCirculationNode)
        {
            FlowNodeView flowNodeView = FlowNodeService.GetFlowNodeByNodeCode(flowCode, false, flowNodeCode);
            lstConditionAndCirculationNode.Add(flowNodeView);
            if (flowNodeView.NodeType == 2)
            {
                //如果是条件节点，获取条件节点的XML数据并解析，递归调用
                string[] arrFlowNodeCode = GetNodeCodeByXMLForCirculation(flowNodeView.NodeXML, recordID);
                foreach (string nextNodeCode in arrFlowNodeCode)
                {
                    GetConditionAndCirculationNode(flowCode, nextNodeCode, recordID, processUserDepartment, lstCirculationNode, lstConditionAndCirculationNode);
                }
            }
            else
            {
                if (!string.IsNullOrEmpty(flowNodeView.NodeXML))
                {
                    flowNodeView.DefaultProcessPerson = GetDefaultProcessPerson(flowNodeView.NodeXML, processUserDepartment);
                }
                lstCirculationNode.Add(flowNodeView);
            }
        }

        /// <summary>
        /// 获取缺省处理人和部门
        /// </summary>
        /// <param name="docPerson">节点xml文档</param>
        /// <param name="recordID">单据ID</param>
        /// <returns></returns>
        private string GetDefaultProcessPerson(string nodeXML, string processUserDepartment)
        {
            string defaultProcessPerson = string.Empty;
            XmlDocument docPerson = new XmlDocument();
            docPerson.LoadXml(nodeXML);
            XmlNode personNode = docPerson.SelectSingleNode("NodeXML/defaultProcessPerson");
            if (personNode != null)
            {
                string processPersonGetType = personNode.SelectSingleNode("getType").InnerText;
                if (processPersonGetType == "value")
                {
                    defaultProcessPerson = personNode.SelectSingleNode("presonList").InnerText;
                }
                else
                {
                    string functionName = personNode.SelectSingleNode("functionName").InnerText;
                    Hashtable para = new Hashtable();
                    para.Add("OrgCode", processUserDepartment);
                    XmlNode paraNode = personNode.SelectSingleNode("functionParam");
                    if (paraNode != null)
                    {
                        para.Add(paraNode.Name, paraNode.InnerText);
                    }
                    defaultProcessPerson = FlowUtilsService.ExecuteCommand(functionName, para) as string;
                }
            }
            return defaultProcessPerson;
        }
        #endregion

        #region 施工合同计量器选择
        public ActionResult ConstructionContractEstimateList(string contractID, string handleState, string sourceType, string processType, string associatedNodeCode, string lastUpdateUserDepartment, string lastUpdateUser, string expenseID)
        {
            SelectConstructionContractEstimateView view = new SelectConstructionContractEstimateView();
            view.ContractID = contractID.ToGuid();
            view.HandleState = handleState;
            view.SourceType = sourceType;
            view.ProcessType = processType;
            view.AssociatedNodeCode = associatedNodeCode;
            view.LastUpdateUserDepartment = lastUpdateUserDepartment;
            view.LastUpdateUser = lastUpdateUser;
            view.ExpenseID = expenseID;
            return View(view);
        }

        //已经没用了，被泽新改成GetVMEstimateDataList
        public ActionResult GetConstructionContractEstimateList(string contractID, string sourceType, string processType, string associatedNodeCode, string lastUpdateUserDepartment, string lastUpdateUser, string expenseID)
        {
            if ((sourceType == "0" && processType == "2") || sourceType == "1" || (sourceType == "2" && processType == "1"))
            {
                return Json(ExpenseService.GetConstructionContractEstimateBackupList(contractID.ToGuid(), expenseID.ToGuid(), associatedNodeCode, lastUpdateUserDepartment, lastUpdateUser));
            }
            else
            {
                return Json(ExpenseService.GetConstructionContractEstimateList(contractID.ToGuid(), expenseID.ToGuid()));
            }
        }
        #endregion

        [HttpPost]
        [ValidateInput(false)]
        public ActionResult Save(ExpenseView model, string vilidateCirculation)
        {
            try
            {
                string message = ValidateMoney(model);
                if (string.IsNullOrEmpty(message))
                {
                    if (vilidateCirculation == "1")
                    {
                        message = CanCirculation(model.FlowCode, model.ExpenseID.ToString(), model.AssociatedNodeCode, model.LastUpdateUserDepartment);
                        if (string.IsNullOrEmpty(message))
                        {
                            SaveData(model);
                            return Content("保存成功!");
                        }
                        else
                        {
                            return Content(message);
                        }
                    }
                    else
                    {
                        SaveData(model);
                        return Content("保存成功!");
                    }
                }
                else
                {
                    return Content(message);
                }

            }
            catch (Exception ex)
            {
                return Content("保存失败：" + ex.Message);
            }
        }

        public string ValidateMoney(ExpenseView model)
        {
            string message = string.Empty;
            if (model.ContractSource == "Construction")
            {
                List<ConstructionContractEstimateView> lstConstructionContractEstimateView = ExpenseService.GetConstructionContractEstimateBackupList(model.ContractID, model.ExpenseID, model.AssociatedNodeCode, model.LastUpdateUserDepartment, model.LastUpdateUser);
                if (!string.IsNullOrEmpty(model.ExpenseBillListJson as string))
                {
                    string expenseBillListJsonNew = "{\"lstConstructionContractEepenseBillView\":" + model.ExpenseBillListJson + "}";
                    XmlNode expenseBillListNode = XMLJsonUtils.JsonToXml(expenseBillListJsonNew).SelectSingleNode("root/lstConstructionContractEepenseBillView");
                    foreach (XmlNode childNode in expenseBillListNode.ChildNodes)
                    {
                        string contractStages = childNode.SelectSingleNode("ContractStages").InnerText;
                        decimal? contractStagesMoney = Convert.ToDecimal(childNode.SelectSingleNode("RequestMoney").InnerText);
                        ConstructionContractEstimateView constructionContractEstimateView = lstConstructionContractEstimateView.SingleOrDefault(c => c.ContractStages == contractStages);
                        if (constructionContractEstimateView != null && contractStagesMoney > (constructionContractEstimateView.ContractStagesMoney - constructionContractEstimateView.ApprovalMoney))
                        {
                            message += "【" + contractStages + "】、";
                        }
                    }
                    if (!string.IsNullOrEmpty(message))
                    {
                        message = "选择的期次" + message.Trim('、') + "的本次申请金额超过了批复金额减去已付款金额，请重新填写！";
                    }
                }
            }
            else
            {
                bool isPass = ExpenseService.IsPassMoneyForCommonContractExpense(model.ContractID, model.ExpenseID, model.ApprovalMoney);
                if (isPass)
                {
                    message = "本次申请金额超过了合同金额减去其他付款申请合计金额，请重新填写！";
                }
            }
            return message;
        }

        #region 判断是否能发送
        public string CanCirculation(string flowCode, string recordID, string currentFlowNodeCode, string processUserDepartment)
        {
            //分析当前节点的XML里面的circulationCell，获取节点Code数组
            FlowNodeView flowNodeView = FlowNodeService.GetFlowNodeByNodeCode(flowCode, false, currentFlowNodeCode);
            string[] arrFlowNodeCode = GetNodeCodeByXMLForCirculation(flowNodeView.NodeXML, recordID);

            string message = string.Empty;
            bool isEnd = arrFlowNodeCode.Length == 1 && arrFlowNodeCode[0].ToLower() == "end";
            if (!isEnd)
            {
                //根据第一次获取到的节点数组，获取所有的流转节点
                List<FlowNodeView> lstCirculationNode = new List<FlowNodeView>();
                foreach (string flowNodeCode in arrFlowNodeCode)
                {
                    GetCirculationNode(flowCode, flowNodeCode, recordID, processUserDepartment, lstCirculationNode);
                }

                if (lstCirculationNode.Count > 0)
                {
                    foreach (FlowNodeView circulationNode in lstCirculationNode)
                    {
                        if (string.IsNullOrEmpty(circulationNode.DefaultProcessPerson))
                        {
                            message += "【" + circulationNode.NodeName + "】,";
                        }
                    }
                    if (!string.IsNullOrEmpty(message))
                    {
                        message = "节点" + message.Trim(',') + "没有设置处理人！";
                    }
                }
                else
                {
                    message = "没有发送节点！";
                }
            }
            return message;
        }

        private void GetCirculationNode(string flowCode, string flowNodeCode, string recordID, string processUserDepartment, List<FlowNodeView> lstCirculationNode)
        {
            FlowNodeView flowNodeView = FlowNodeService.GetFlowNodeByNodeCode(flowCode, false, flowNodeCode);
            if (flowNodeView.NodeType == 2)
            {
                //如果是条件节点，获取条件节点的XML数据并解析，递归调用
                string[] arrFlowNodeCode = GetNodeCodeByXMLForCirculation(flowNodeView.NodeXML, recordID);
                foreach (string nextNodeCode in arrFlowNodeCode)
                {
                    GetCirculationNode(flowCode, nextNodeCode, recordID, processUserDepartment, lstCirculationNode);
                }
            }
            else
            {
                if (!string.IsNullOrEmpty(flowNodeView.NodeXML))
                {
                    flowNodeView.DefaultProcessPerson = GetDefaultProcessPerson(flowNodeView.NodeXML, processUserDepartment);
                }
                lstCirculationNode.Add(flowNodeView);
            }
        }
        #endregion

        private void SaveData(ExpenseView model)
        {
            if (model.SourceType == "1")
            {
                ExpenseView expenseView = ExpenseService.GetExpenseBackupByID(model.ID);
                if (expenseView == null)
                {
                    model.ExpenseNum = ExpenseService.GetExpenseNum(model.ProjectID, model.ContractID);
                    List<BaklogTaskView> addList = new List<BaklogTaskView>();
                    addList.Add(new BaklogTaskView()
                    {
                        ID = GuidHelper.NewGuid(),
                        RecordID = model.ExpenseID.ToString(),
                        TaskType = model.FlowCode,
                        RequestDate = model.RequestDate,
                        CurrentFlowNodeCode = model.AssociatedNodeCode,
                        CurrentProcessPersonDepartment = model.LastUpdateUserDepartment,
                        CurrentProcessPerson = model.LastUpdateUser,
                        NodeLevel = 1
                    });
                    BaklogTaskService.AddBaklogTask(addList);
                }
            }
            if (model.HandleState == "0")
            {
                model.RequestMoneyForRequestPerson = model.ApprovalMoney;
            }
            model.LastUpdateTime = DateTime.Now;
            model.SaveState = "1";
            model.SendState = "0";

            List<ConstructionContractEepenseBillView> saveList = new List<ConstructionContractEepenseBillView>();
            if (model.ContractSource == "Construction" && !string.IsNullOrEmpty(model.ExpenseBillListJson as string))
            {
                List<ConstructionContractEepenseBillView> existsList = ExpenseService.GetBillBackupList(model.ExpenseID, model.AssociatedNodeCode, model.LastUpdateUserDepartment, model.LastUpdateUser);

                string expenseBillListJsonNew = "{\"lstConstructionContractEepenseBillView\":" + model.ExpenseBillListJson + "}";
                XmlNode expenseBillListNode = XMLJsonUtils.JsonToXml(expenseBillListJsonNew).SelectSingleNode("root/lstConstructionContractEepenseBillView");
                foreach (XmlNode childNode in expenseBillListNode.ChildNodes)
                {
                    string contractStages = childNode.SelectSingleNode("ContractStages").InnerText;
                    decimal? contractStagesMoney = Convert.ToDecimal(childNode.SelectSingleNode("RequestMoney").InnerText);
                    ConstructionContractEepenseBillView existsBill = existsList.SingleOrDefault(c => c.ContractStages == contractStages);
                    if (existsBill == null)
                    {
                        saveList.Add(new ConstructionContractEepenseBillView()
                        {
                            ID = Guid.NewGuid(),
                            PID = model.ExpenseID,
                            BillID = Guid.NewGuid(),
                            ContractID = model.ContractID,
                            ContractStages = contractStages,
                            ContractStagesMoney = contractStagesMoney,
                            AssociatedNodeCode = model.AssociatedNodeCode,
                            LastUpdateUserDepartment = model.LastUpdateUserDepartment,
                            LastUpdateUser = model.LastUpdateUser,
                            LastUpdateTime = DateTime.Now,
                            SendState = "0"
                        });
                    }
                    else
                    {
                        existsBill.ContractStagesMoney = contractStagesMoney;
                        saveList.Add(existsBill);
                    }
                }
            }
            ExpenseService.SaveExpenseBackup(model, saveList);
        }

        public ActionResult Withdraw(ExpenseView model, string withdrawNodeCode)
        {
            try
            {
                //获取撤回到的节点信息
                FlowNodeView flowNodeView = FlowNodeService.GetFlowNodeByNodeCode(model.FlowCode, false, withdrawNodeCode);
                List<FlowNodeView> lstCirculationNode = new List<FlowNodeView>();
                Dictionary<string, List<FlowNodeView>> dicConditionAndCirculationNode = new Dictionary<string, List<FlowNodeView>>();
                bool isCanWithdraw = CanWithdraw(flowNodeView, model.ExpenseID.ToString(), model.FlowCode, model.ProcessdOrCirculatedUserDepartment, lstCirculationNode, dicConditionAndCirculationNode);
                if (isCanWithdraw)
                {
                    FlowUtilsService.Withdraw(flowNodeView, model.FlowCode, model.ExpenseID.ToString(), model.ProcessdOrCirculatedUserDepartment, model.RequestDate, lstCirculationNode, dicConditionAndCirculationNode);
                    return Content("Success");
                }
                else
                {
                    return Content("已经有人处理，不能撤回！");
                }
            }
            catch (Exception ex)
            {
                return Content(ex.Message);
            }
        }

        public ActionResult Cancel(string flowCode, string id)
        {
            try
            {
                FlowUtilsService.Cancel(flowCode, User.Identity.Name, id);
                ExpenseView expenseView = ExpenseService.GetExpenseByID(id);
                expenseView.HandleState = "3";
                ExpenseService.SaveExpense(expenseView, new List<ConstructionContractEepenseBillView>());
                return Content("Success");
            }
            catch (Exception ex)
            {
                return Content(ex.Message);
            }
        }

        public ActionResult Reminders(string flowCode, string id)
        {
            try
            {
                FlowUtilsService.Reminders(id, flowCode, User.Identity.Name);
                return Content("Success");
            }
            catch (Exception ex)
            {
                return Content(ex.Message);
            }
        }

        public ActionResult GenerateGraph(string flowCode, string id)
        {
            ExpenseView expenseView = ExpenseService.GetExpenseByID(id);
            string handleState = "";
            if (expenseView != null)
            {
                handleState = expenseView.HandleState;
            }
            WorkFlowView workFlowView = FlowUtilsService.GenerateGraph(flowCode, id, handleState);
            return Json(workFlowView, JsonRequestBehavior.AllowGet);
        }

        #region 项目下的合同付款列表
        public ActionResult ContractExpenseList()
        {
            ViewBag.ToolBarInfo = base.GetToolBarInfo();
            //ConstructToolsForList();
            return View();
        }

        public ActionResult GetContractExpenseList(string projectID)
        {
            string correspondenceUnitStr = string.Empty;
            List<Guid> lstCorrespondenceUnit = new List<Guid>();
            GetCorrespondenceUnitInfo(ref correspondenceUnitStr, ref lstCorrespondenceUnit);
            return Json(ExpenseService.GetContractExpenseList(projectID, correspondenceUnitStr, lstCorrespondenceUnit), JsonRequestBehavior.AllowGet);
        }

        private void GetCorrespondenceUnitInfo(ref string correspondenceUnitStr, ref List<Guid> lstCorrespondenceUnit)
        {
            //获取需要做合同筛选的顶级部门，如果不为空并且不是超级管理员，则需要对登陆用户的拨付款列表进行筛选：只能查看登陆用户所属部门或者子部门与客户端合同对应单位相同的那些
            string topDepartmentOfNeedFilterContractStr = ConfigurationManager.AppSettings["TopDepartmentOfNeedFilterContract"] as string;
            if (!string.IsNullOrEmpty(topDepartmentOfNeedFilterContractStr) && SystemData.Instance.CurrentUser.UserType == UserType.Common)
            {
                //获取登陆用户的机构信息
                List<OrgInfo> orgs = (from u in UserInfoService.Users
                                      join uo in UserOrgService.UserOrgs on u.ID equals uo.UserID
                                      join o in OrgInfoService.Orgs on uo.OrgID equals o.ID
                                      where u.UserName == User.Identity.Name
                                      select o).ToList();
                if (orgs.Count() > 0)
                {
                    //获取能新增施工合同的所有部门
                    List<Guid> lstAllAddConstructionContractDepartment = new List<Guid>();
                    string[] addConstructionContractTopDepartmentArr = topDepartmentOfNeedFilterContractStr.Split(',');
                    foreach (string addConstructionContractTopDepartment in addConstructionContractTopDepartmentArr)
                    {
                        OrgInfo orgInfo = OrgInfoService.Orgs.SingleOrDefault(o => o.OrgCode == addConstructionContractTopDepartment);
                        if (orgInfo != null)
                        {
                            lstAllAddConstructionContractDepartment.Add(orgInfo.ID);
                            FlowFilterAndRequestUtils.GetSubOrgInfo(orgInfo.ID, ref lstAllAddConstructionContractDepartment);
                        }
                    }

                    //如果所有能新增施工合同的机构包含登陆用户所在部门，则需要筛选数据
                    if (FlowFilterAndRequestUtils.IsContainLoginOrg(lstAllAddConstructionContractDepartment, orgs))
                    {
                        foreach (var org in orgs)
                        {
                            correspondenceUnitStr += "'" + org.ID + "',";
                            lstCorrespondenceUnit.Add(org.ID);
                            GetSubCorrespondenceUnit(org.ID, ref correspondenceUnitStr, ref lstCorrespondenceUnit);
                        }
                        correspondenceUnitStr = correspondenceUnitStr.Trim(',');
                    }
                }
            }
        }

        ////获取指定部门的下级部门
        //private void GetSubOrgInfo(Guid parentID, ref List<Guid> lstAllAddConstructionContractDepartment)
        //{
        //    IQueryable<OrgInfo> lstOrgInfo = OrgInfoService.Orgs.Where(o => o.PID == parentID);
        //    foreach (OrgInfo orgInfo in lstOrgInfo)
        //    {
        //        lstAllAddConstructionContractDepartment.Add(orgInfo.ID);
        //        GetSubOrgInfo(orgInfo.ID, ref lstAllAddConstructionContractDepartment);
        //    }
        //}

        ////所有能新增施工合同的机构是否包含登陆用户所在部门
        //private bool IsContainLoginOrg(List<Guid> lstAllAddConstructionContractDepartment, List<OrgInfo> orgs)
        //{
        //    foreach (OrgInfo org in orgs)
        //    {
        //        if (lstAllAddConstructionContractDepartment.Contains(org.ID))
        //        {
        //            return true;
        //        }
        //    }
        //    return false;
        //}

        private void GetSubCorrespondenceUnit(Guid parentID, ref string correspondenceUnitStr, ref List<Guid> lstCorrespondenceUnit)
        {
            IQueryable<OrgInfo> lstOrgInfo = OrgInfoService.Orgs.Where(o => o.PID == parentID);
            foreach (OrgInfo orgInfo in lstOrgInfo)
            {
                correspondenceUnitStr += "'" + orgInfo.ID.ToString() + "',";
                lstCorrespondenceUnit.Add(orgInfo.ID);
                GetSubCorrespondenceUnit(orgInfo.ID, ref correspondenceUnitStr, ref lstCorrespondenceUnit);
            }
        }
        #endregion

        #region 合同下的付款期次列表以及删除选中项
        public ActionResult ExpenseList(string projectID, string contractID, string contractName, string contractSource, string contractMoney, string constructionDrawMoney, string alterIncreaseOrDecreaseMoney, string afterAlterMoney, string approvalMoney, string paymentPercentage)
        {
            //ViewBag.ToolBarInfo = base.GetToolBarInfo();
            ConstructToolsForList(contractID, contractSource);
            ContractExpenseView view = new ContractExpenseView();
            view.ProjectID = projectID.ToGuid();
            view.ContractID = contractID.ToGuid();
            view.ContractName = contractName;
            view.ContractSource = contractSource;
            view.ContractMoney = Convert.ToDecimal(contractMoney);
            view.ConstructionDrawMoney = Convert.ToDecimal(constructionDrawMoney);
            view.AlterIncreaseOrDecreaseMoney = Convert.ToDecimal(alterIncreaseOrDecreaseMoney);
            view.AfterAlterMoney = Convert.ToDecimal(afterAlterMoney);
            view.ApprovalMoney = Convert.ToDecimal(approvalMoney);
            view.PaymentPercentage = paymentPercentage;
            return View(view);
        }

        /// <summary>
        /// 构造新增删除的功能按钮，首先判断当前用户所具有的机构在不在流程的申请节点的预定义机构里，然后判断当前用户是否对当前合同有权限
        /// </summary>
        /// <param name="contractID">合同ID</param>
        /// <param name="contractSource">合同来源</param>
        private void ConstructToolsForList(string contractID, string contractSource)
        {
            //获取所选合同的对应单位的编码
            Guid correspondenceUnit = Guid.Empty;
            if (contractSource == "Construction")
            {
                string sql = "select * from V_ContractInfoes where id='" + contractID + "'";
                List<VMContractInfo> lstVMContractInfo = DbSqlHelper<VMContractInfo>.SqlQueryCommon(sql);
                if (lstVMContractInfo != null && lstVMContractInfo.Count == 1 && lstVMContractInfo[0].CorrespondenceUnit != null && lstVMContractInfo[0].CorrespondenceUnit != Guid.Empty)
                {
                    correspondenceUnit = lstVMContractInfo[0].CorrespondenceUnit.Value;
                }
            }
            else
            {
                Guid contractIDGuid = contractID.ToGuid();
                ContractInfoView contractInfoView = CommonContractInfoService.GetCommonContractInfo(contractIDGuid);
                if (contractInfoView != null && contractInfoView.CorrespondenceUnit != Guid.Empty)
                {
                    correspondenceUnit = contractInfoView.CorrespondenceUnit;
                }
            }
            string correspondenceUnitCode = string.Empty;
            if (correspondenceUnit != Guid.Empty)
            {
                OrgInfo orgInfo = OrgInfoService.Orgs.SingleOrDefault(o => o.ID == correspondenceUnit);
                if (orgInfo != null)
                {
                    correspondenceUnitCode = orgInfo.OrgCode;
                }
            }

            //如果所选合同的对应单位的编码不为空进行权限判断
            StringBuilder sb = new StringBuilder();
            List<UIFunctionView> menuActions = base.GetUserMenuActions();
            if (!string.IsNullOrEmpty(correspondenceUnitCode))
            {
                var orgs = (from u in UserInfoService.Users
                            join uo in UserOrgService.UserOrgs on u.ID equals uo.UserID
                            join o in OrgInfoService.Orgs on uo.OrgID equals o.ID
                            where u.UserName == User.Identity.Name
                            select o).ToList();
                if (orgs.Count() > 0)
                {
                    string requestDepartmentListForExpense = ConfigurationManager.AppSettings["RequestDepartmentListForExpense"] as string;
                    foreach (var orgInfo in orgs)
                    {
                        if (orgInfo.OrgCode == correspondenceUnitCode && CommonUtils.FlowFilterAndRequestUtils.IsHasOrgCodeAndUserNameInStr(requestDepartmentListForExpense, orgInfo.OrgCode, User.Identity.Name))
                        {
                            foreach (UIFunctionView item in menuActions)
                            {
                                if (!item.ActionCode.Equals("ReverseAudit"))
                                {
                                    string btn = "<a href='javascript:void(0)' id='btn" + item.ActionCode + "' class='easyui-linkbutton' onclick='" + item.MenuCode + "." + item.ActionCode + "()' data-options='plain:true,iconCls:\"" + item.Icon + "\"'>" + item.ActionName + "</a>";
                                    sb.Append(btn);
                                }
                            }
                            break;
                        }
                    }
                }
            }

            if (User.Identity.Name.Equals("baiq"))
            {
                foreach (UIFunctionView item in menuActions)
                {
                    if (item.ActionCode.Equals("ReverseAudit"))
                    {
                        string btn = "<a href='javascript:void(0)' id='btn" + item.ActionCode + "' class='easyui-linkbutton' onclick='" + item.MenuCode + "." + item.ActionCode + "()' data-options='plain:true,iconCls:\"" + item.Icon + "\"'>" + item.ActionName + "</a>";
                        sb.Append(btn);
                    }
                }
            }

            ViewBag.ToolBarInfo = sb.ToString();
        }

        public ActionResult GetExpenseList(string contractID)
        {
            List<ExpenseView> lstExpenseView = ExpenseService.GetExpenseList(contractID.ToGuid());
            SetProcedureMonitor(lstExpenseView);
            return Json(lstExpenseView, JsonRequestBehavior.AllowGet);
        }

        private void SetProcedureMonitor(List<ExpenseView> lstExpenseView)
        {
            foreach (ExpenseView expenseView in lstExpenseView)
            {
                expenseView.ContractStagesStr = "第" + expenseView.ContractStages + "期";
                string procedureMonitor = string.Empty;
                if (expenseView.HandleState == "0")
                {
                    List<BaklogTaskView> lstBaklogTaskView = BaklogTaskService.GetBaklogTaskByRecordID(expenseView.ExpenseID.ToString());
                    if (lstBaklogTaskView.Count == 1)
                    {
                        string nodeName = FlowNodeService.GetFlowNodeByNodeCode(expenseView.FlowCode, true, "").NodeName;
                        string realName = lstBaklogTaskView[0].CurrentProcessPerson;
                        var userInfo = UserInfoService.GetUserInfoByName(lstBaklogTaskView[0].CurrentProcessPerson);
                        if (userInfo != null && !string.IsNullOrEmpty(userInfo.RealName))
                        {
                            realName = userInfo.RealName;
                        }
                        procedureMonitor = "由【" + nodeName + "】【" + realName + "】申请";
                    }
                }
                else if (expenseView.HandleState == "2" || expenseView.HandleState == "3")
                {
                    List<ProcessedTaskView> lstProcessedTaskView = ProcessedTaskService.GetProcessedTaskListByHandleState(expenseView.ExpenseID.ToString(), expenseView.HandleState);
                    if (lstProcessedTaskView.Count == 1)
                    {
                        string nodeName = lstProcessedTaskView[0].CurrentProcessNodeName;
                        string realName = lstProcessedTaskView[0].CurrentProcessPerson;
                        var userInfo = UserInfoService.GetUserInfoByName(lstProcessedTaskView[0].CurrentProcessPerson);
                        if (userInfo != null)
                        {
                            realName = userInfo.RealName;
                        }
                        if (expenseView.HandleState == "2")
                        {
                            procedureMonitor = "已由【" + nodeName + "】【" + realName + "】审批完成";
                        }
                        else
                        {
                            procedureMonitor = "已由【" + nodeName + "】【" + realName + "】终止";
                        }
                    }
                }
                else
                {
                    List<BaklogTaskView> lstBaklogTaskView = BaklogTaskService.GetBaklogTaskByRecordID(expenseView.ExpenseID.ToString());
                    if (lstBaklogTaskView.Count > 0)
                    {
                        string nodeName = FlowNodeService.GetFlowNodeByNodeCode(expenseView.FlowCode, false, lstBaklogTaskView[0].CurrentFlowNodeCode).NodeName;
                        string realName = string.Empty;
                        foreach (BaklogTaskView baklogTaskView in lstBaklogTaskView)
                        {
                            string userName = baklogTaskView.CurrentProcessPerson;
                            var userInfo = UserInfoService.GetUserInfoByName(userName);
                            if (userInfo != null && !string.IsNullOrEmpty(userInfo.RealName))
                            {
                                userName = userInfo.RealName;
                            }
                            realName += userName + ",";
                        }
                        if (!string.IsNullOrEmpty(realName))
                        {
                            realName = realName.Trim(',');
                        }
                        procedureMonitor = "正在等待【" + nodeName + "】【" + realName + "】审批";
                    }
                }
                expenseView.ProcedureMonitor = procedureMonitor;
            }
        }

        public ActionResult DeleteSelectExpense()
        {
            string expenseID = Request["expenseID"];
            var result = ExpenseService.DeleteSelectExpense(expenseID);
            if (result.ResultType == OperationResultType.Success)
                return Content(OperationResultType.Success.ToString());
            return Content(result.Message);
        }        
        #endregion

        #region 详细信息（支表一、二、三）
        /// <summary>
        /// 支表一-上（列表）
        /// </summary>
        /// <param name="keyID"></param>
        /// <returns></returns>
        public ActionResult GetVMExpenseFirstTopList(string sectionID, int? periodID)
        {
            //此处暂时取演示数据
            //VMExpenseFirstDemoData demo = new VMExpenseFirstDemoData();
            //List<VMExpenseFirstTopList> listView = demo.GetVMExpenseFirstTopList(sectionID, periodID);

            //虚构
            //periodID = 1;

            //真实数据
            var listView = ExpenseService.GetVMExpenseFirstTopList(sectionID, periodID == null ? 0 : periodID.Value);
            return Json(listView, JsonRequestBehavior.AllowGet);
        }

        /// <summary>
        /// 支表一-下（列表）
        /// </summary>
        /// <param name="keyID"></param>
        /// <returns></returns>
        public ActionResult GetVMExpenseFirstBottomList(string sectionID, int? periodID)
        {
            //此处暂时取演示数据
            //VMExpenseFirstDemoData demo = new VMExpenseFirstDemoData();
            //List<VMExpenseFirstBottomList> listView = demo.GetVMExpenseFirstBottomList(sectionID, periodID);

            //虚构
            //periodID = 1;

            //真实数据
            var listView = ExpenseService.GetVMExpenseFirstBottomList(sectionID, periodID == null ? 0 : periodID.Value);
            return Json(listView, JsonRequestBehavior.AllowGet);
        }

        /// <summary>
        /// 支表一-扣款（列表）
        /// </summary>
        /// <param name="keyID"></param>
        /// <returns></returns>
        public ActionResult GetVMExpenseFirstCutPaymentList(string sectionID, int? periodID)
        {
            //此处暂时取演示数据
            //VMExpenseFirstDemoData demo = new VMExpenseFirstDemoData();
            //List<VMExpenseFirstCutPayment> listView = demo.GetVMExpenseFirstCutPaymentList(sectionID, periodID);

            //虚构
            //periodID = 1;

            //真实数据
            var listView = ExpenseService.GetVMExpenseFirstCutPaymentList(sectionID, periodID == null ? 0 : periodID.Value);
            return Json(listView, JsonRequestBehavior.AllowGet);
        }

        public ActionResult GetVMExpenseSecondList(string sectionID, int? periodID)
        {
            //真实数据
            var listView = ExpenseService.GetVMExpenseSecondList(sectionID, periodID == null ? 0 : periodID.Value);
            return Json(listView, JsonRequestBehavior.AllowGet);
        }

        /// <summary>
        /// 支表三（列表）
        /// </summary>
        /// <param name="sectionID">标段ID</param>
        /// <param name="periodID">期次ID</param>
        /// <returns></returns>
        public ActionResult GetVMExpenseThirdList(string sectionID, int? periodID)
        {
            //此处暂时取演示数据
            //VMExpenseThirdDemoData demo = new VMExpenseThirdDemoData();
            //List<VMExpenseThirdList> listView = demo.GetVMExpenseThirdList(sectionID);

            //虚构
            //periodID = 1;

            //真实数据
            var listView = ExpenseService.GetVMExpenseThirdList(sectionID, periodID == null ? 0 : periodID.Value);
            return Json(listView, JsonRequestBehavior.AllowGet);
        }
        #endregion

        #region 计量数据--luozx
        public ActionResult GetVMEstimateDataList(string sectionID)
        {
            //真实数据
            var listView = ExpenseService.GetVMEstimateDataList(sectionID);
            return Json(listView, JsonRequestBehavior.AllowGet);
        }

        public ActionResult UpdateConstructionContractEstimate(string contractID, string contractStages)
        {
            try
            {
                return Json(ExpenseService.GetUpdateConstructionContractEstimate(contractID, contractStages), JsonRequestBehavior.AllowGet);
            }
            catch (Exception ex)
            {
                return Json(new UpdateConstructionContractEstimateView() { ApproveMoney = 0, Message = ex.Message }, JsonRequestBehavior.AllowGet);
            }
        }
        #endregion

        public ActionResult GenerateChart(string projectID, string contractID, int periodID)
        {
            LineView lineView = new LineView();
            string totalReviseMoney = YearPlanService.GetTotalReviseMoney(projectID.ToGuid(), "", contractID.ToGuid());
            List<VMQCYearMonth> lstVMQCYearMonth = ExpenseService.GetVMQCYearMonth(contractID, periodID);
            if (!string.IsNullOrEmpty(totalReviseMoney))
            {
                lineView.lstPointView = YearPlanService.GetYearPlanComplete(projectID.ToGuid(), contractID.ToGuid(), Convert.ToDouble(totalReviseMoney));

                if (lstVMQCYearMonth.Count == 1)
                {
                    VMQCYearMonth vmQCYearMonth = lstVMQCYearMonth.First();
                    lineView.lstPointViewOne = MonthPlanService.GetMonthPlanComplete(projectID.ToGuid(), contractID.ToGuid(), Convert.ToDouble(totalReviseMoney), vmQCYearMonth.Year, vmQCYearMonth.Month);
                }
            }

            lineView.lstPointViewTwo = ExpenseService.GetZFComplete(contractID, periodID);
            return Json(lineView, JsonRequestBehavior.AllowGet);
        }

        #region 进度查询
        public ActionResult ScheduleSearchList()
        {
            ViewBag.ToolBarInfo = base.GetToolBarInfo();
            return View();
        }

        public ActionResult GetScheduleSearchList(string projectID, string contractType, string contractIDStr)
        {
            LineView lineView = new LineView();
            if (!string.IsNullOrEmpty(projectID) && !string.IsNullOrEmpty(contractIDStr))
            {
                List<Guid> lstContractID = new List<Guid>();
                List<string> lstContractStrID = new List<string>();
                string contractIDSQLWhere = string.Empty;
                string[] contractIDArr = contractIDStr.Split(',');
                foreach (string contractID in contractIDArr)
                {
                    lstContractID.Add(contractID.ToGuid());
                    lstContractStrID.Add(contractID);
                    contractIDSQLWhere += "'" + contractID + "',";
                }

                string totalReviseMoney = YearPlanService.GetTotalReviseMoneyForMulContract(projectID.ToGuid(), contractType, lstContractID);
                if (!string.IsNullOrEmpty(totalReviseMoney))
                {
                    lineView.lstPointView = YearPlanService.GetYearPlanCompleteForMulContract(projectID, contractType, contractIDSQLWhere.TrimEnd(','), lstContractID, Convert.ToDecimal(totalReviseMoney));

                    lineView.lstPointViewOne = MonthPlanService.GetMonthPlanCompleteForMulContract(projectID.ToGuid(), contractType, lstContractID, Convert.ToDecimal(totalReviseMoney));
                }

                lineView.lstPointViewTwo = ExpenseService.GetZFCompleteForMulContract(projectID, lstContractStrID, contractIDSQLWhere.TrimEnd(','));
            }
            return Json(lineView, JsonRequestBehavior.AllowGet);
        }
        #endregion

        #region 支表二报表获取拨付款信息
        public ActionResult GetExpenseByProjectIDAndContractID(string projectID, string contractID)
        {
            List<ExpenseView> lstExpenseView = ExpenseService.GetExpenseByProjectIDAndContractID(projectID.ToGuid(), contractID.ToGuid());
            return Json(lstExpenseView, JsonRequestBehavior.AllowGet);
        }
        #endregion
    }
}